﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


using CCWin;
using BookModel;
using BLL;
namespace WinFromBook
{
    public partial class FrmReadInfodrop : CCSkinMain
    {
        public FrmReadInfodrop()
        {
            InitializeComponent();
        }
        #region 封装方法，字段，执行操作


        ReaderInfoBLL bll = new ReaderInfoBLL();
        //加载
        public void LoadInfo()
        {
            this.listViewBorrower.Items.Clear();
            List<ReaderInfo> list = bll.selectread();
            foreach (var item in list)
            {
                ListViewItem lvi = new ListViewItem(item.ReaderID + "");
                lvi.SubItems.Add(item.ReaderName);
                lvi.SubItems.Add(item.ReaderSex);
                lvi.SubItems.Add(item.ReaderCard);
                lvi.SubItems.Add(item.ReaderPhone);
                lvi.SubItems.Add(item.ReaderAge + "");
                lvi.SubItems.Add(item.ReaderopenDate + "");
                lvi.SubItems.Add(item.ReaderCancelDate + "");
                lvi.SubItems.Add(item.Readeremark);

                this.listViewBorrower.Items.Add(lvi);
            }
        }
        //查询
        public void GetInfo()
        {
            if (String.IsNullOrEmpty(ReaderName.Text.Trim()))
            {
                LoadInfo();
                return;
            }
            this.listViewBorrower.Items.Clear();
            List<ReaderInfo> list = bll.selectread();
            foreach (var item in list)
            {
                if (item.ReaderName.Contains(ReaderName.Text.Trim()))
                {
                    ListViewItem lvi = new ListViewItem(item.ReaderID + "");
                    lvi.SubItems.Add(item.ReaderName);
                    lvi.SubItems.Add(item.ReaderSex);
                    lvi.SubItems.Add(item.ReaderCard);
                    lvi.SubItems.Add(item.ReaderPhone);
                    lvi.SubItems.Add(item.ReaderAge + "");
                    lvi.SubItems.Add(item.ReaderopenDate + "");
                    lvi.SubItems.Add(item.ReaderCancelDate + "");
                    lvi.SubItems.Add(item.Readeremark);
                    this.listViewBorrower.Items.Add(lvi);
                }
            }
        }
        //注销事件
        public void Cancel()
        {
            if (listViewBorrower.SelectedItems.Count <= 0)
                return;
            DialogResult dr = MessageBox.Show("确认注销读者：" + listViewBorrower.SelectedItems[0].SubItems[1].Text + "吗？", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr==DialogResult.OK)
            {
                int ReaderID = int.Parse(listViewBorrower.SelectedItems[0].SubItems[0].Text);

                string sql = new BLL.ReaderInfoBLL().UpdateRead(ReaderID);
                MessageBox.Show(sql, "系统提示");
                LoadInfo();
            }
        }
        #endregion
        private void FrmReadInfodrop_Load(object sender, EventArgs e)
        {
            LoadInfo();
        }
      
        private void skinbtnSelect_Click(object sender, EventArgs e)
        {
            GetInfo();
        }

        private void 读者注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cancel();
        }
    }
}
